package com.dhcc.cdc.busi.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.busi.entity.CdcLabSensEntity;
import com.dhcc.cdc.busi.service.ICdcLabSensService;
import com.dhcc.core.framework.annotion.BussinessLog;
import com.dhcc.core.framework.annotion.Permission;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * 药敏结果
 * 
 * @ClassName: LabSensController
 * @Description: TODO
 * @author jumper
 * @date 2021-04-26 16:21:40
 */
@Controller
@RequestMapping("${sys.backendPath}/cdc/labsens")
public class CdcLabSensController extends BaseController {

	private String PREFIX = "/backend/cdc/labsens/";

	@Autowired
	private ICdcLabSensService labSensService;
	

    /**
     * 跳转到药敏结果列表首页
     */
    @RequestMapping("")
    @Permission("labsens:list")
    public String index() {
        return PREFIX + "labsens.html";
    }
	
    /**
     * 跳转到新增药敏结果
     */
    @RequestMapping("/to_add")
    @Permission("labsens:add")
    public String toAdd() {
        return PREFIX + "labsens_add.html";
    }
	
	/**
     * 跳转到修改药敏结果
     */
    @RequestMapping("/to_update/{labSensId}")
    @Permission("labsens:update")
    public String toUpdate(@PathVariable Long labSensId, Model model) {
        CdcLabSensEntity labSens = this.labSensService.selectById(labSensId);
        model.addAttribute("labSens",labSens);
        return PREFIX + "labsens_edit.html";
    }

    /**
     * 获取药敏结果列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    @Permission("labsens:list")
    public Object list(@RequestParam Map<String, Object> params) {
		Page<CdcLabSensEntity> page = new PageFactory<CdcLabSensEntity>().defaultPage();
        List<CdcLabSensEntity> result = this.labSensService.page(page,params);
        page.setRecords((List<CdcLabSensEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增药敏结果
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @Permission("labsens:add")
    @BussinessLog(value = "新增药敏结果")
    public Object add(CdcLabSensEntity labSens) {
        if (CommonUtil.isOneEmpty(labSens)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        labSens.insert();
        return R.ok();
    }

    /**
     * 删除药敏结果
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @Permission("labsens:delete")
    @BussinessLog(value = "删除药敏结果")
    public Object delete(@RequestParam Long labSensId) {
	
        this.labSensService.deleteById(labSensId);

        return R.ok();
    }

    /**
     * 修改药敏结果
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    @Permission("labsens:update")
    @BussinessLog(value = "修改药敏结果")
    public Object update(CdcLabSensEntity labSens) {
        if (CommonUtil.isOneEmpty(labSens)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        CdcLabSensEntity old = this.labSensService.selectById(labSens.getId());

        old.setLabResultId(labSens.getLabResultId());
        old.setCode(labSens.getCode());
        old.setDescription(labSens.getDescription());
        old.setSensitivity(labSens.getSensitivity());
        old.setDataId(labSens.getDataId());
        old.setIsActive(labSens.getIsActive());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
